/**************************************************************************************************
**                                                                                               **
**  文件名称:  bsp_irq_drv.c                                                                     **
**  版权所有:  CopyRight @ Xiamen Yaxon NetWork CO.LTD. 2017                                     **
**  文件描述:  用户自定义中断函数                                                                **
**  ===========================================================================================  **
**  创建信息:  | 2017-3-20 | LEON | 创建本模块                                                   **
**  ===========================================================================================  **
**  修改信息:  单击此处添加....                                                                  **
**************************************************************************************************/
#include "bsp_include.h"
#include "bsp_irq_drv.h"
#include "bsp_irq_def.h"
#include "bsp_run_man.h"

__attribute__ ((section ("VECTOR_RAM")))  IRQ_SERVICE_FUNC g_vector_tbl[IRQ_ID_MAX] = 
{
    (IRQ_SERVICE_FUNC)0,
    (IRQ_SERVICE_FUNC)0,
    (IRQ_SERVICE_FUNC)NMIException,
    (IRQ_SERVICE_FUNC)HardFaultException,
    (IRQ_SERVICE_FUNC)MemManageException,
    (IRQ_SERVICE_FUNC)BusFaultException,
    (IRQ_SERVICE_FUNC)UsageFaultException,
    (IRQ_SERVICE_FUNC)0,
    (IRQ_SERVICE_FUNC)0,                 
    (IRQ_SERVICE_FUNC)0,                
    (IRQ_SERVICE_FUNC)0,                 
    (IRQ_SERVICE_FUNC)SVCHandler,
    (IRQ_SERVICE_FUNC)DebugMonitor,
    (IRQ_SERVICE_FUNC)0,                 
    (IRQ_SERVICE_FUNC)PendSVC,
    (IRQ_SERVICE_FUNC)SysTick_Handler,
    (IRQ_SERVICE_FUNC)WWDG_IRQHandler,
    (IRQ_SERVICE_FUNC)PVD_IRQHandler,
    (IRQ_SERVICE_FUNC)TAMP_STAMP_IRQHandler,
    (IRQ_SERVICE_FUNC)RTC__WKUP_IRQHandler,
    (IRQ_SERVICE_FUNC)FLASH_IRQHandler,
    (IRQ_SERVICE_FUNC)RCC_IRQHandler,
    (IRQ_SERVICE_FUNC)EXTI0_IRQHandler,
    (IRQ_SERVICE_FUNC)EXTI1_IRQHandler,
    (IRQ_SERVICE_FUNC)EXTI2_IRQHandler,
    (IRQ_SERVICE_FUNC)EXTI3_IRQHandler,
    (IRQ_SERVICE_FUNC)EXTI4_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA1_Stream0_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA1_Stream1_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA1_Stream2_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA1_Stream3_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA1_Stream4_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA1_Stream5_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA1_Stream6_IRQHandler,
    (IRQ_SERVICE_FUNC)ADC_IRQHandler,
    (IRQ_SERVICE_FUNC)CAN1_TX_IRQHandler,
    (IRQ_SERVICE_FUNC)CAN1_RX0_IRQHandler,
    (IRQ_SERVICE_FUNC)CAN1_RX1_IRQHandler,
    (IRQ_SERVICE_FUNC)CAN1_SCE_IRQHandler,
    (IRQ_SERVICE_FUNC)EXTI9_5_IRQHandler,
    (IRQ_SERVICE_FUNC)TIM1_BRK_TIM9_IRQHandler,
    (IRQ_SERVICE_FUNC)TIM1_UP_TIM10_IRQHandler,
    (IRQ_SERVICE_FUNC)TIM1_TRG_COM_TIM11_IRQHandler,
    (IRQ_SERVICE_FUNC)TIM3_IRQHandler,
    (IRQ_SERVICE_FUNC)TIM4_IRQHandler,
    (IRQ_SERVICE_FUNC)I2C1_EV_IRQHandler,
    (IRQ_SERVICE_FUNC)I2C1_ER_IRQHandler,
    (IRQ_SERVICE_FUNC)I2C2_EV_IRQHandler,
    (IRQ_SERVICE_FUNC)I2C2_ER_IRQHandler,
    (IRQ_SERVICE_FUNC)SPI1_IRQHandler,
    (IRQ_SERVICE_FUNC)SPI2_IRQHandler,
    (IRQ_SERVICE_FUNC)USART1_IRQHandler, 
    (IRQ_SERVICE_FUNC)USART2_IRQHandler,
    (IRQ_SERVICE_FUNC)USART3_IRQHandler,
    (IRQ_SERVICE_FUNC)EXTI15_10_IRQHandler,
    (IRQ_SERVICE_FUNC)RTC_Alarm_IRQHandler,
    (IRQ_SERVICE_FUNC)OTG_FS_WKUP_IRQHandler,
    (IRQ_SERVICE_FUNC)TIM8_BRK_TIM12_IRQHandler,
    (IRQ_SERVICE_FUNC)TIM8_UP_TIM13_IRQHandler,
    (IRQ_SERVICE_FUNC)TIM8_TRG_COM_TIM14_IRQHandler,
    (IRQ_SERVICE_FUNC)TIM8_CC_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA1_Stream7_IRQHandler,
    (IRQ_SERVICE_FUNC)FMC_IRQHandler,
    (IRQ_SERVICE_FUNC)SDIO_IRQHandler,
    (IRQ_SERVICE_FUNC)TIM5_IRQHandler,
    (IRQ_SERVICE_FUNC)SPI3_IRQHandler,
    (IRQ_SERVICE_FUNC)UART4_IRQHandler,
    (IRQ_SERVICE_FUNC)UART5_IRQHandler,
    (IRQ_SERVICE_FUNC)TIM6_DAC_IRQHandler,
    (IRQ_SERVICE_FUNC)TIM7_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA2_Stream0_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA2_Stream1_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA2_Stream2_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA2_Stream3_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA2_Stream4_IRQHandler,
    (IRQ_SERVICE_FUNC)ETH_IRQHandler,
    (IRQ_SERVICE_FUNC)ETH_WKUP_IRQHandler,
    (IRQ_SERVICE_FUNC)CAN2_TX_IRQHandler,
    (IRQ_SERVICE_FUNC)CAN2_RX0_IRQHandler,
    (IRQ_SERVICE_FUNC)CAN2_RX1_IRQHandler,
    (IRQ_SERVICE_FUNC)CAN2_SCE_IRQHandler,
    (IRQ_SERVICE_FUNC)OTG_FS_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA2_Stream5_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA2_Stream6_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA2_Stream7_IRQHandler,
    (IRQ_SERVICE_FUNC)USART6_IRQHandler,
    (IRQ_SERVICE_FUNC)I2C3_EV_IRQHandler,
    (IRQ_SERVICE_FUNC)I2C3_ER_IRQHandler,
    (IRQ_SERVICE_FUNC)OTG_HS_EP1_OUT_IRQHandler,
    (IRQ_SERVICE_FUNC)OTG_HS_EP1_IN_IRQHandler,
    (IRQ_SERVICE_FUNC)OTG_HS_WKUP_IRQHandler,
    (IRQ_SERVICE_FUNC)OTG_HS_IRQHandler,
    (IRQ_SERVICE_FUNC)DCMI_IRQHandler,
    (IRQ_SERVICE_FUNC)CRYP_IRQHandler,
    (IRQ_SERVICE_FUNC)HASH_RNG_IRQHandler,
    (IRQ_SERVICE_FUNC)FPU_IRQHandler,
    (IRQ_SERVICE_FUNC)UART7_IRQHandler,
    (IRQ_SERVICE_FUNC)UART8_IRQHandler,
    (IRQ_SERVICE_FUNC)SPI4_IRQHandler,
    (IRQ_SERVICE_FUNC)SPI5_IRQHandler,
    (IRQ_SERVICE_FUNC)SPI6_IRQHandler,
    (IRQ_SERVICE_FUNC)SAI1_IRQHandler,
    (IRQ_SERVICE_FUNC)LTDC_IRQHandler,
    (IRQ_SERVICE_FUNC)LTDC_ER_IRQHandler,
    (IRQ_SERVICE_FUNC)DMA2D_IRQHandler
};

/**************************************************************************************************
**  函数名称:  BSP_InstallIRQHandler
**  功能描述:  安装中断处理函数
**  输入参数:  irqid: 中断号; handle: 中断处理函数
**  输出参数:  无
**  返回参数:  无
**************************************************************************************************/
void BSP_InstallIRQHandler(INT32S irqid, IRQ_SERVICE_FUNC handle)
{
    SYS_ASSERT(((irqid > -16) && (irqid + 16 < IRQ_ID_MAX)), RETURN_VOID);
    SYS_ASSERT((handle != 0), RETURN_VOID);
    
    ENTER_CRITICAL();
    g_vector_tbl[irqid + 16] = handle;
    EXIT_CRITICAL();
}

/**************************************************************************************************
**  函数名称:  BSP_ConfigIRQPriority
**  功能描述:  配置中断优先级
**  输入参数:  irqid: 中断号; pree_pr: 主优先级; sub_pr: 子优先级
**  输出参数:  无
**  返回参数:  无
**************************************************************************************************/
void BSP_ConfigIRQPriority(INT32S irqid, INT32U pree_pr, INT32U sub_pr)
{
    SYS_ASSERT(((irqid > -16) && (irqid + 16 < IRQ_ID_MAX)), RETURN_VOID);
    
    ENTER_CRITICAL();
	NVIC_SetPriority((IRQn_Type)irqid, sub_pr);
	EXIT_CRITICAL();
}

/**************************************************************************************************
**  函数名称:  BSP_ConfigIRQEnable
**  功能描述:  配置中断开启或关闭
**  输入参数:  irqid: 中断号; enable: TRUE:使能中断, false-关闭中断
**  输出参数:  无
**  返回参数:  无
**************************************************************************************************/
void BSP_ConfigIRQEnable(INT32S irqid, BOOLEAN enable)
{
    SYS_ASSERT(((irqid >= -16) && (irqid + 16 < IRQ_ID_MAX)), RETURN_VOID);
    
    if (enable) {
        ENTER_CRITICAL();
        NVIC_EnableIRQ((IRQn_Type)irqid);
        EXIT_CRITICAL();
    } else {
        ENTER_CRITICAL();
        NVIC_DisableIRQ((IRQn_Type)irqid);
        EXIT_CRITICAL();
    }
}

